package com.spring.controller;

import com.jntoo.db.*;
import com.spring.entity.Yonghu;
import com.spring.service.YonghuService;
import com.spring.util.*;
import java.util.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ForgetController extends BaseController {

    @Resource
    private YonghuService yonghuService;

    @RequestMapping("/forget")
    public String forget() {
        String cx = "";
        String step = Request.get("step", "1");
        int sp = Integer.valueOf(step).intValue();

        String username = "";
        String daan = "";
        String xmm = "";
        Map user = null;
        if (sp > 1) {
            cx = Request.get("cx");
            username = Request.get("username");
            /*查看模块 */
            if (cx.equals("用户")) {
                user = Query.make("yonghu").where("yonghuming", username).find();
            }
            /* 结束模块 */

            if (user.isEmpty()) {
                return showError("没有找到该用户");
            }
            assign("username", username);
            assign("wenti", user.get("wenti"));
            assign("cx", cx);
        }
        if (sp > 2) {
            daan = Request.get("daan");
            if (!daan.equals(user.get("daan"))) {
                return showError("答案错误，请重新填写");
            }
            assign("daan", daan);
        }
        if (sp > 3) {
            xmm = Request.get("xmm");
            if (cx.equals("用户")) {
                yonghuService.updatePassword(Integer.valueOf(user.get("id").toString()).intValue(), xmm);
            }
        }
        assign("step", step);
        if (isAjax()) {
            return json();
        }
        return "forget";
    }
}
